﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp5.Students
{
    public partial class Add : Form
    {
        public Add()
        {
            InitializeComponent();
        }

        private void Add_Load(object sender, EventArgs e)
        {
            comboBox1.Text = "男";
            comboBox2.DataSource = WJNDBEntities.dbhelp.Class.ToList();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string sid = tb1.Text.Trim();
            string sname = tb2.Text.Trim();
            string sex = comboBox1.Text.Trim();
            string cno = comboBox2.Text.Trim();
            Student s = new Student();
            s.SNo = sid; s.SName = sname; s.Gender = sex; s.CNo = cno;
            try
            {
                WJNDBEntities.dbhelp.Student.Add(s);
                WJNDBEntities.dbhelp.SaveChanges();
                MessageBox.Show("提交成功！");
               
            }
            catch (Exception)
            {
                MessageBox.Show("提交失败！");
            }
            finally
            {
                this.Close();
            }
            
        }

       
    }
}
